package com.lxl.hadoop.wc;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @Author lixilin
 * @Date 2021/12/5 8:37
 * KEYIN :输入数据的key
 * VALUEIN: 输入数据的value
 * KEYOUT : 输出数据的key
 * VALUEOUT: 输出数据的value
 * @Description
 */
public class WcMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
    Text k = new Text();
    IntWritable v = new IntWritable(1);
    protected void map(LongWritable key, Text value,
                       Context context) throws IOException, InterruptedException {
        // atguigu atguigu
        System.out.println(key.toString());
        // 获取一行
        String line = value.toString();
        // 切割单词
        String[] words = line.split(" ");
        // 循环写出
        for (String word : words) {
            // atguigu 1
            k.set(word);
            context.write(k,v);
        }

    }
}
